import { store } from '../store'
import { loginTokenSlice } from '../toolkitSlice/loginTokenSlice'

function listenerHandle() {
  store.dispatch(
    loginTokenSlice.actions.updateLoginToken(
      localStorage.getItem('baseToken') || ''
    )
  )
}

export function storageListener() {
  window.addEventListener('storage', listenerHandle)

  return () => {
    window.removeEventListener('storage', listenerHandle)
  }
}
